package com.learner.course.controller.api;


import com.learner.common.util.JwtInfo;
import com.learner.common.util.JwtUtils;
import com.learner.course.service.CourseCommentService;
import com.learner.pojo.course.CourseComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Description: 课程评论的接口
 * @Author: ice2020x
 * @Date: 2021/11/12
 */
@RestController
@RequestMapping("/api/edu/comment")
public class ApiCourseCommentController {


    @Autowired
    CourseCommentService courseCommentService;

    /**
     * 查询课程评论的
     *
     * @param courseId 课程id
     * @param context  课程内容
     * @return 结果
     */
    @PostMapping("/auth/save/{courseId}")
    public CourseComment save(@PathVariable("courseId") String courseId, HttpServletRequest request, String context) {
        JwtInfo memberIdByJwtToken = JwtUtils.getInfoByJwtToken(request);
        return courseCommentService.save(courseId, memberIdByJwtToken, context);
    }

    /**
     * 删除一条评论
     *
     * @param commentId 评论id
     */
    @DeleteMapping("/auth/delete/{commentId}")
    public void delete(@PathVariable("commentId") String commentId) {
        courseCommentService.delete(commentId);
    }

    /**
     * 查询课程评论的
     *
     * @param courseId 课程id
     * @return 结果
     */
    @GetMapping("/comment/list/courses/{courseId}")
    public List<CourseComment> findCommentListById(@PathVariable("courseId") String courseId) {
        return courseCommentService.findCommentListById(courseId);
    }
}
